package com.eke.action.user;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;

import com.eke.bean.Article;
import com.eke.bean.UserConcern;
import com.eke.service.ArticleService;
import com.eke.service.UserConcernService;
import com.jason.mvc.annotations.Ajax;
import com.jason.mvc.annotations.Namespace;
import com.jason.mvc.annotations.RequestMapping;
import com.jason.mvc.utils.ApplicationContext;

@Namespace("/userConcern")
@Component("userConcernAction")
@Scope(WebApplicationContext.SCOPE_REQUEST)
public class UserConcernAction {
	@Resource
	private UserConcernService userConcernService;
	@Resource
	private ArticleService articleService;
	private UserConcern userConcern;

	private Article article;
	

	/**
	 * 是否已经关注用户
	 * 
	 * @return
	 */
	@RequestMapping("isConcern")
	@Ajax(true)
	public Map<String, Object> isConcern() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("result", userConcernService.isAddUserConcern(userConcern.getUserId(), userConcern.getUseConcernId()));
		return map;
	}

//	/**
//	 * 关注用户
//	 * 
//	 * @return
//	 */
//	@RequestMapping("addUserConCern")
//	@Ajax(true)
//	public Map<String, Object> addUserConCern() {
//		Map<String, Object> map = new HashMap<String, Object>();
//		Article ac=articleService.queryArticleByArticleId(article.getArticleId());
//		javax.servlet.http.HttpSession session = ApplicationContext.getSession();
////		Enumeration<String> names = session.getAttributeNames();
//		if (session.getAttribute("users.userId") != null) {
//			Integer userId = (Integer) session.getAttribute("users.userId");
//			userConcern.setUserId(userId);
//			userConcern.setUseConcernId(ac.getUserId());
//			map.put("result", userConcernService.addUserConcern(userConcern));
//		}
//		
//
//		return map;
//	}
	
	/**
	 * 关注用户
	 * 
	 * @return
	 */
	@RequestMapping("addUserConCern")
	@Ajax(true)
	public Map<String, Object> addUserConCern() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("result", userConcernService.addUserConcern(userConcern));
		return map;
	}


	/**
	 * 取消关注用户
	 * 
	 * @return
	 */
	@RequestMapping("deletUserConCern")
	@Ajax(true)
	public Map<String, Object> deletUserConCern() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("result", userConcernService.cencelUserConcern(userConcern.getUserId(), userConcern.getUseConcernId()));
		return map;
	}

}
